package com.gc.gc.duty.service.impl;

import com.gc.gc.duty.entity.DutyServiceEnity;
import com.gc.gc.duty.repository.DutyDao;
import com.gc.gc.duty.service.DutyService;
import com.gc.gc.mybatis.entity.PtDutyEntity;
import com.gc.gc.mybatis.flexigrid.PadingRstType;
import com.gc.gc.mybatis.flexigrid.PagingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class DutyServiceImpl implements DutyService {
    @Resource
    private DutyDao dutyDao;
    @Override
    public PadingRstType<PtDutyEntity> getDutyInfolistByPage(DutyServiceEnity search, PagingBean paging) {
        paging.deal(PtDutyEntity.class);
        PadingRstType<PtDutyEntity> padingRstType = new PadingRstType<>();
        padingRstType.setPage(paging.getPage());
        List<PtDutyEntity> list = dutyDao.queryDutyListByPage(search,paging);
        Integer total = dutyDao.queryDutyListTotal(search);
        padingRstType.setTotal(total);
        padingRstType.setRawRecords(list);
        padingRstType.putItems();
        return padingRstType;
    }

    @Override
    public void addDuty(DutyServiceEnity search) {
        String dutyid = UUID.randomUUID().toString(); //36
        dutyid = dutyid.replace("-",""); //32
        search.setDutyId(dutyid);
        dutyDao.addDuty(search);
    }

    @Override
    public void deleteDutyById(String dutyid) {
        dutyDao.deleteDutyById(dutyid);
    }
}
